package com.youlv.yl.util;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.youlv.yl.config.SystemConfig;
import org.json.JSONObject;

/**
 * @author fenghe
 * @date 2022/1/12 20:27
 */
public class BaiduContentUtils {
    /** 内容审核对象*/
    public static final AipContentCensor censor = new AipContentCensor(SystemConfig.BAIDU_APPID, SystemConfig.BAIDU_KEY, SystemConfig.BAIDU_SEC);

    /** 图片审核*/
    public static boolean imgCensor(byte[] data) {
        // 进行图片审核
        JSONObject response = censor.imageCensorUserDefined(data, null);
        // 返回审核结果
        return response.getInt("conclusionType") == 1;
    }

    /** 文本审核*/
    public static boolean textCensor(String txt) {
        // 文本审核
        JSONObject response = censor.textCensorUserDefined(txt);
        // 返回审核结果
        return response.getInt("conclusionType") == 1;
    }
}
